﻿using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using BO;

namespace DAL.SysManagerDAL
{
    public class SMStartDateDAL
    {
        string ConnString = ConfigurationManager.ConnectionStrings["AMIE_DB"].ToString();
        
        public SMStartDateDAL() { }

        public int Insert (FiscalYear fy, WriteLog wl )
        {
            SqlConnection conn = new SqlConnection(ConnString);

            conn.Open();

            SqlCommand cmd = new SqlCommand("STP_InsertFiscalYearTable", conn);

            cmd.CommandType = CommandType.StoredProcedure;
            try
            {
                cmd.Parameters.Add(new SqlParameter("@StartDate", SqlDbType.DateTime, 50));
                cmd.Parameters["@StartDate"].Value = fy.StartDate;
                cmd.Parameters.Add(new SqlParameter("@UserID", SqlDbType.Int, 10));
                cmd.Parameters["@UserID"].Value = fy.RegisterId;
                cmd.Parameters.Add(new SqlParameter("@IP", SqlDbType.NVarChar, 50));
                cmd.Parameters["@IP"].Value = wl.Ip;
                cmd.Parameters.Add(new SqlParameter("@ControlDate", SqlDbType.DateTime, 50));
                cmd.Parameters["@ControlDate"].Value = wl.ControlDate;
                cmd.Parameters.Add(new SqlParameter("@JobModId", SqlDbType.Int, 50));
                cmd.Parameters["@JobModId"].Value = wl.JobModId;
                cmd.Parameters.Add(new SqlParameter("@success", SqlDbType.Int, 4));
                cmd.Parameters["@success"].Direction = ParameterDirection.Output;

                return cmd.ExecuteNonQuery();
            }
            catch
            {
                throw;
            }
            finally
            {
                cmd.Dispose();
                conn.Close();
                conn.Dispose();
            }
        }

        
    }
}
